package com.leiyu.Config

import com.alibaba.druid.pool.DruidDataSource
import com.jfinal.config._
import com.jfinal.core.JFinal
import com.jfinal.plugin.activerecord.ActiveRecordPlugin
import com.jfinal.render.ViewType
import com.jfinal.template.Engine
import com.leiyu.control.{IndexControl, WriteControl}
import com.leiyu.model.Blog


/**
  * Created by LeiYu on 2017/6/20.
  */
class MainConfig extends JFinalConfig{
  override def configConstant(me: Constants): Unit = {
    //开发者模式+模板引擎配置
    me.setDevMode(true)
    me.setViewType(ViewType.JSP)
  }

  override def configPlugin(plugins: Plugins): Unit = {
    val data = new DruidDataSource()
    data.setDriverClassName("com.mysql.jdbc.Driver")
    data.setUrl("jdbc:mysql://47.93.223.39:3306/blog?useUnicode=true&characterEncoding=utf8")
    data.setUsername("root")
    data.setPassword("tb132123")
    val arp = new ActiveRecordPlugin(data)
    plugins.add(arp)
    arp.addMapping("t_blog",classOf[Blog])


  }

  override def configEngine(engine: Engine): Unit = {}

  override def configHandler(handlers: Handlers): Unit = {}

  override def configInterceptor(interceptors: Interceptors): Unit = {}

  override def configRoute(me: Routes): Unit = {
    me.add("/",classOf[IndexControl])
    me.add("/write",classOf[WriteControl])
  }
}

object MainConfig{
  def main(args: Array[String]): Unit = {
    JFinal.start("web",8080,"/",20)
  }
}

